﻿using JamesZhao.Engine.GameObjects;
using JamesZhao.Engine.Graphics.Visuals;

namespace JamesZhao.Engine.GameComponents
{
    internal class LightComponent : GameComponent
    {
        private readonly Light _light;

        public LightComponent(GameObject owner) : base(owner)
        {
            _light = Engine.GraphicsManager.VisualsList.AttachNewLight();
            _light.LightCamera.Lens.AspectRatio = 1;
            _light.LightCamera.Lens.FieldOfView = 3.14f/2f;
            _light.LightCamera.Lens.Near = 1;
            _light.LightCamera.Lens.Far = 200;
        }

        public float Intensity { get; set; }

        public bool IsShadowed { get; set; }

        public override void Update()
        {
            base.Update();
            _light.LightCamera.Position = Transform.LocalPosition;
            _light.LightCamera.Forward = Transform.Forward;
            _light.LightCamera.Up = Transform.Up;
            _light.Intensity = Intensity;
            _light.IsShadowed = IsShadowed;
        }
    }
}